import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/constants.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/buttons/floatingActionButtonCreateAssignment.dart';
import 'package:ichinesereader/widgets/buttons/myFavoriteButtonBar.dart';
import 'package:ichinesereader/widgets/grids/bookGridWithCheckBoxTeaching.dart';

class MyFavoriteReadingBookTeacherPage extends StatefulWidget {
  static const String routeName = '/teacher/myfavorites';

  _MyFavoriteReadingBookTeacherPage createState() =>
      new _MyFavoriteReadingBookTeacherPage();
}

class _MyFavoriteReadingBookTeacherPage
    extends State<MyFavoriteReadingBookTeacherPage> {
  final BooksController controller = Get.find();

  @override
  void initState() {
    // Future.delayed(Duration(milliseconds: 600), () {
    //   controller.selectedFavoriteReadingBookItemsClear();
    // });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build MyLibraryReadingBookTeacherPage');
    var box = Hive.box('appconfig');
    bool isTeacher = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Teacher;
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: isSmallScreen
          ? Column(
              children: [
                Container(
                  height: 120,
                  margin: EdgeInsets.only(top: 9.0),
                  child: isTeacher ? FavoriteButtonBar() : Text(''),
                ),
                Expanded(
                    child: controller.obx(
                  (data) => BookGridWithCheckBoxTeaching(
                    books: controller.myFavoriteBookItems,
                    readingType: NanhaiBookReadingTypes.favorite,
                  ),
                  onEmpty: Center(child: Text('No book has been added'.tr)),
                  onLoading: Container(),
                )),
              ],
            )
          : Column(
              children: [
                Container(
                  height: 60.0,
                  margin: EdgeInsets.only(top: 12.0),
                  child: isTeacher ? FavoriteButtonBar() : Text(''),
                ),
                Expanded(
                    child: controller.obx(
                  (data) => BookGridWithCheckBoxTeaching(
                    books: controller.myFavoriteBookItems,
                    readingType: NanhaiBookReadingTypes.favorite,
                  ),
                  onEmpty: Center(child: Text('No book has been added'.tr)),
                  onLoading: Container(),
                )),
              ],
            ),
      floatingActionButton: FloatingActionButtonCreateAssignment(),
    );
  }
}
